home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / lcube.c.bak < prev    next >
Text File  |  1997-11-05  |  4KB  |  199 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #ifdef SGI
  5. #include "gl.h"
  6. #include "device.h"
  7. #include "hershey.h"
  8. #else
  9. #include "vogl.h"
  10. #include "vodevice.h"
  11. #endif
  12.  
  13. /* ---------------------------------------------------------------------
  14.  * Definitions:
  15.  */
  16.  
  17. #define    CUBE_SIZE    200.0
  18. #define    TRANS        25.0
  19. #define    SCAL        0.1
  20.  
  21. /* ---------------------------------------------------------------------
  22.  * Prototypes:
  23.  */
  24. int main(void);                                        /* lcube.c         */
  25. int makecubes(int);                                    /* lcube.c         */
  26.  
  27.  
  28. /* ---------------------------------------------------------------------
  29.  * Source Code:
  30.  */
  31.  
  32. int main(void)
  33. {
  34.         char    *p;
  35.     float    tdir = TRANS;
  36.     float    scal = 1.0 + SCAL;
  37.     int    but, nplanes;
  38.     int    x, y, i, n;
  39.     short    val;
  40.     int kivon=-1;
  41.  
  42.     prefsize(300L, 300L);
  43.  
  44.     winopen("lcube");
  45.  
  46.     unqdevice(INPUTCHANGE);
  47.     qdevice(SKEY);
  48.     qdevice(XKEY);
  49.     qdevice(YKEY);
  50.     qdevice(ZKEY);
  51.     qdevice(EQUALKEY);
  52.     qdevice(MINUSKEY);
  53.     qdevice(ESCKEY);
  54.     qdevice(QKEY);
  55.     
  56.  
  57.     window(-300.0, 300.0, -300.0, 300.0, -300.0, 300.0);
  58.     lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);
  59.  
  60.     if ((nplanes = getplanes()) == 1)
  61.         makecubes(0);
  62.  
  63.     makecubes(1);
  64.  
  65.     backface(1);
  66.         
  67.     doublebuffer();
  68.     gconfig();
  69.  
  70.     /*
  71.      * Doublebuffer does a backbuffer(TRUE)....
  72.      */
  73.  
  74.     while(1) {
  75.         x = 500 - (int)getvaluator(MOUSEX);
  76.         y = 500 - (int)getvaluator(MOUSEY);
  77.         x *= 3;
  78.         y *= 3;
  79.         
  80.         pushmatrix();
  81.             rotate(x, 'y');
  82.             rotate(y, 'x');
  83.             color(BLACK);
  84.             clear();
  85.             callobj(3);
  86.             if (nplanes == 1)
  87.                 callobj(2);
  88.         popmatrix();
  89.         swapbuffers();
  90.  
  91.         if (qtest()) {
  92.             but = qread(&val);
  93.             but = qread(&val);    /* swallow up event */
  94.  
  95.             switch (but) {
  96.  
  97.             case SKEY:
  98.                 scale(scal, scal, scal);
  99.                 break;
  100.             case XKEY:
  101.                 translate(tdir, 0.0, 0.0);
  102.                 break;
  103.             case YKEY:
  104.                 translate(0.0, tdir, 0.0);
  105.                 break;
  106.             case ZKEY:
  107.                 translate(0.0, 0.0, tdir);
  108.                 break;
  109.             case MINUSKEY:
  110.                 tdir = -tdir;
  111.  
  112.                 if (scal < 1.0)
  113.                     scal = 1.0 + SCAL;
  114.                 else
  115.                     scal = 1.0 - SCAL;
  116.  
  117.                 break;
  118.             case EQUALKEY:
  119.                 tdir = TRANS;
  120.                 break;
  121.             case ESCKEY:
  122.             case QKEY:
  123.                 gexit();
  124.                 exit(0);
  125.             default:
  126.                 ;
  127.             }
  128.         }
  129.     }
  130. }
  131.  
  132. void    makecubes(int fill)
  133. {
  134.     makeobj((fill + 2));
  135.         if (!fill)
  136.             color(BLACK);
  137.  
  138.         pushmatrix();
  139.             translate(0.0, 0.0, CUBE_SIZE);
  140.             if (fill) {
  141.                 color(RED);
  142.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  143.             } else
  144.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  145.         popmatrix();
  146.  
  147.         pushmatrix();
  148.             translate(CUBE_SIZE, 0.0, 0.0);
  149.             rotate(900, 'y');
  150.             if (fill) {
  151.                 color(GREEN);
  152.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  153.             } else
  154.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  155.         popmatrix();
  156.  
  157.         pushmatrix();
  158.             translate(0.0, 0.0, -CUBE_SIZE);
  159.             rotate(1800, 'y');
  160.             if (fill) {
  161.                 color(BLUE);
  162.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  163.             } else 
  164.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  165.         popmatrix();
  166.  
  167.         pushmatrix();
  168.             translate(-CUBE_SIZE, 0.0, 0.0);
  169.             rotate(-900, 'y');
  170.             if (fill) {
  171.                 color(CYAN);
  172.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  173.             } else
  174.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  175.         popmatrix();
  176.  
  177.         pushmatrix();
  178.             translate(0.0, CUBE_SIZE, 0.0);
  179.             rotate(-900, 'x');
  180.             if (fill) {
  181.                 color(MAGENTA);
  182.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  183.             } else
  184.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  185.         popmatrix();
  186.  
  187.         pushmatrix();
  188.             translate(0.0, -CUBE_SIZE, 0.0);
  189.             rotate(900, 'x');
  190.             if (fill) {
  191.                 color(YELLOW);
  192.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  193.             } else
  194.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  195.         popmatrix();
  196.  
  197.     closeobj();
  198. }
  199.